<%@ taglib uri="http://java.sun.com/portlet" prefix="portlet" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<jsp:useBean id="myprop" class="java.lang.String" scope="request"/>
<!--jsp:useBean id="dataList" class="java.util.ArrayList" scope="request"/-->

<portlet:defineObjects/>

<!--Load the AJAX API-->
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
    google.load("visualization", "1", {packages:["corechart"]});
    google.setOnLoadCallback(drawAvgChart);
    google.setOnLoadCallback(drawErrorsChart);

    function drawAvgChart() {
        var data = new google.visualization.DataTable();
        data.addColumn('string', 'Year');
        data.addColumn('number', 'Sales');
        data.addRows(${dataListSize});

    <% int i = 0;%>
    <c:forEach var="data" items="${dataList}">
        data.setValue(<%= i %>, 0, '<%= 2004 + i %>');
        data.setValue(<%= i %>, 1, ${data.avgResponseTime});
    <% i++; %>
    </c:forEach>

        var chart = new google.visualization.LineChart(document.getElementById('avg_chart'));
        chart.draw(data, {width: 400, height: 240, title: 'Average'});
    }

    function drawErrorsChart() {
        var data = new google.visualization.DataTable();
        data.addColumn('string', 'Errors');
        data.addColumn('number', 'Sales');
        data.addRows(${dataListSize});

    <% int j = 0;%>
    <c:forEach var="data" items="${dataList}">
        data.setValue(<%= j %>, 0, '<%= 2004 + j %>');
        data.setValue(<%= j %>, 1, ${data.errors});
    <% j++; %>
    </c:forEach>

        var chart = new google.visualization.LineChart(document.getElementById('errors_div'));
        chart.draw(data, {width: 400, height: 240, title: 'Errors'});
    }
</script>


<p>This is the Nudge portlet.</p>

<p>From properties file <%=myprop %>!</p>

<!--Div that will hold the Average chart-->
<div id="avg_chart"></div>

<!--Div that will hold the Errors chart-->
<div id="errors_div"></div>
